package com.common;

import com.corundumstudio.socketio.SocketIOClient;
import com.corundumstudio.socketio.SocketIOServer;
import com.netty.MessageInfo;

import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * 通用类
 *
 * @author chenfuqiang
 */
public class Global {
	/**
	 * 版本号
	 */
	public static final String VERSION = "VALE.ALPHA";


	/**
	 * 设置ext的主题
	 */
	public static Object THEME = "ext-all-neptune";
	public static final String ENCODE = "UTF-8";
	//=========================固定参数=======================================//
	//模板所在路径
	public static final String TEMPLATEPATH = "//com//auto//service//ftl";
	//SocketIO
	public static SocketIOServer server;
	//NETTY
	public static final UUID CLIENTUUID = new UUID(123, 123);
	public static final UUID SERVERID = new UUID(321, 321);

	public static void Send(String msg) {
		Collection<SocketIOClient> clients = Global.server.getAllClients();
		for (SocketIOClient s : clients) {
			MessageInfo sendData = new MessageInfo();
			sendData.setMsgType("chat");
			sendData.setMsgContent(msg);
			s.sendEvent("messageevent", sendData);
		}
	}

	//解析并自动生成代码所在包名
	public static final String PACKAGEOFCODER_TREE = "com.auto.service.impl.coder.tree";
	public static final String PACKAGEOFCODER_LIST = "com.auto.service.impl.coder.list";
	public static final String JS_APPLICATION_PACKAGE = "app.application";
	public static final String JS_CONTROLLER_PACKAGE = "app.controller";
	public static final String JS_MODEL_PACKAGE = "app.model";
	public static final String JS_STORE_PACKAGE = "app.store";
	public static final String JS_VIEW_PACKAGE = "app.view";
	public static final String AUTHOR = "Tim[ATC.Pro Generate]";
	//pojo bean 所在包
	public static String PACKAGEOFPOJO = "com.pojo";

	//==========================手动配置参数===============================//
	//目标项目的pojo bean 所在的包名
	public static final String PACKAGEOFTARGETPOJO = "com.main.pojo.prfm";

	//==========================页面配置参数===============================//
	//代码所在的路径
	public static String WORKSPACEPROPATH;
	//具体代码所在项目路径  普通项目只要 //src 这里是maven项目所以延伸到java
	public static String SRCPATH;
	//controller
	public static String CONTROLLER_PACKAGE;
	//service
	public static String SERVICE_PACKAGE;
	//serviceImpl
	public static String SERVICEIMPL_PACKAGE;
	//dao
	public static String DAO_PACKAGE;
	//mapping
	public static String MAPPING_PACKAGE;
	public static String WEBSRCPATH;
	public static String JSSRCPATH;
	public static String JSP_PACKAGE;

	/**
	 * 强制删除文件，有时候不会成功。如果是被其他程序占用。
	 * @param f
	 * @return
	 */
	public static boolean forceDelete(File f){
		boolean result = false;
		int tryCount = 0;
		while(!result && tryCount++ <10){
			System.gc();
			result = f.delete();
		}
		return result;
	}

}
